#include <iostream>
#include <string>
#include "threadpool.hpp"

#define QUIT "quit"

using namespace LogModule;
using namespace ThreadPoolModule;

void test()
{
    // std::cout << "mysql version : " << mysql_get_client_info() << "\n";

    MYSQL* my = mysql_init(nullptr);
    if(my == nullptr)
    {
        std::cerr << "mysql_init fail" << "\n";
        return;
    }
    // 连接数据库的函数
    MYSQL* tem = mysql_real_connect(my, host, user, password, db, port, nullptr, 0);
    if(tem == nullptr)
    {
        std::cerr << "connect fail " << mysql_error(my) << "\n";
        return;
    }
    std::cout << "connect success" << "\n";

    std::string instruction = "delete from student where name='杨八'";
    // std::string instruction = "insert into student (name, tel, gender, class) values('杨八', '1234566789', '男', 1)";
    int ret = mysql_query(my, instruction.c_str());
    if(ret != 0)
    {
        std::cout << "query fail " << mysql_error(my) << "\n";
        return;
    }

    mysql_close(my);
    return;
}


int main()
{
    // 开启控制器日志模式
    ENABLECONSOLELOGSTRATEGY();
    std::unique_ptr<threadpool<std::string>> tp = std::make_unique<threadpool<std::string>>();
    tp->Start();

    std::string instruction;
    while(true)
    {
        std::cout << "Mysql>> ";
        getline(std::cin, instruction);
        if(instruction == QUIT)
        {
            LOG(LEVEL::DEBUG) << "quit mysql, bye";
            break;
        }
        tp->Equeue(std::move(instruction));
    }

    tp->Stop();
    
    return 0;
}